require('../../assets/css/index.less');
require("../../assets/fitness-font/iconfont.css");

require('./home.less');

require("swiper/dist/css/swiper.min.css");
//引入swiper
const mySwiper = require('swiper');

// 引入axios
const axios = require('../../utils/axios.js');

// 底部导航
const nav = require('../../utils/nav.js');
nav.showNav('home');

// 引入window
const { $, g } = require('../../utils/dom')
/**
 * window加载事件
 */
$(function () {
    /**
     * swiper轮播图
     */
    let mySwiper = new Swiper('.swiper', {

        autoplay: 2000,

        loop: true, // 循环模式选项
        // autoplayDisableOnInteraction : false,

        // 如果需要分页器
        pagination: '.swiper-pagination',
    })

    /**
     * 获取用户信息
     */
    axios.get('/api/user/info').then((res) => {
        if (res.data.errno === 0) {
            // 渲染数据
            g('#rankbox').textContent = res.data.data.ranking
            g('#badgesNum').textContent = res.data.data.badges + `枚`
            g('#clockday').textContent = res.data.data.clockCount
        }
    })

    /**
     * 打卡
     */
    clockBtn.addEventListener('click', () => {
        axios.post('/api/user/clockIn').then((res) => {
            if (res.data.errno === 0) {
                g('#clockday').textContent = +clockday.textContent + 1;
                g('#clockBtn').textContent = '今日已打卡';
            } else {
                alert(res.data.message);
            }
        })
    })

    /**
     * 获取用户打卡信息
     */
    axios.get('/api/user/clockInInfo').then((res) => {
        if (res.data.errno === 0) {
            g('#clockBtn').textContent = res.data.data.isClockIn ? '今日已打卡' : '今日打卡';
        }
    })
})

